function BigNumber(i) {
    this.number = [];
    var tmp=i, tmp1, tmp2;
    do {
        tmp1 = tmp%1000;
        tmp = (tmp-tmp1)/1000;
        this.number.push(tmp1);
    } while(tmp>1000)
}

BigNumber.prototype.add = function(addNumber) {
    var tmp1=0, tmp2=0, tmp3=0;
    
    var len1 = this.number.length;
    var len2 = addNumber.number.length;
    var length = (len1>len2) ? len1 : len2;
    for(var i=0; i< length; i++) {
        tmp1  = (this.number[i] || 0) + (addNumber.number[i] || 0) + tmp2;
        tmp3 = tmp1%1000;
        this.number[i] = tmp3;
        tmp2 = (tmp1-tmp3)/1000;
    }
    do {
        tmp1 = tmp2%1000;
        tmp2 = (tmp2-tmp1)/1000;
        if(tmp1>0 || tmp2>0) this.number.push(tmp1);
    } while(tmp2>1000)    
}

BigNumber.prototype.times = function(a) {
    var tmp, tmp1=0, tmp2=0, tmp3=0;
    for(var i=0; i< this.number.length; i++) {
        tmp  = this.number[i];
        tmp1 = tmp * a + tmp2;
        tmp3 = tmp1%1000;
        this.number[i] = tmp3;
        tmp2 = (tmp1-tmp3)/1000;
    }
    do {
        tmp1 = tmp2%1000;
        tmp2 = (tmp2-tmp1)/1000;
        if(tmp1>0 || tmp2>0)this.number.push(tmp1);
    } while(tmp2>1000)    
    //print("*" + a + "=" + this.number + "," + this.toString());
}

BigNumber.prototype.toString = function() {
    var s = [];
    for(var i=0; i<this.number.length; i++) {
        if(this.number.length-1-i!=0) {
            s[this.number.length-1-i] = (this.number[i]+1000).toString().substr(1,3);
        } else {
            s[this.number.length-1-i] = this.number[i];
        }
    }
    return s.join("");
}

BigNumber.prototype.countDigital = function() {
    var count, n1 = this.number[this.number.length-1];
    count = 1;
    if(n1>10) count = 2;
    if(n1>100) count = 3;
    return (this.number.length-1)*3 + count;
}

function p25() {
    var f1 = new BigNumber(1), f2 = new BigNumber(1), f3;
    var term = 2;
    while(1) {
        f1.add(f2); 
        f3 = f1; 
        f1 = f2;
        f2 = f3;
        term++;
        print("F("+term+")="+f3.countDigital());
        if(f3.countDigital()>1000) return term;
        
    }
    
}

print(p25());
